﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Aletfa.LightManager
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private GameManager Manager { get; set; }

        public MainWindow()
        {
            InitializeComponent();
            this.Manager = new GameManager();
            this.Manager.BoardSetup += manager_BoardSetup;
            this.Manager.Units.ListChanged += Units_ListChanged;
            this.Manager.UnitLifeChanged += Manager_UnitLifeChanged;
            this.Manager.UnitChanged += Manager_UnitChanged;
            this.Board.Initialize(5, 5);
            this.Console.Initialize(this.Manager);

            this.Board.SelectionChanged += Board_SelectionChanged;
        }

        void Board_SelectionChanged(Unit arg)
        {
            this.Test.Datasource = arg;
        }

        void Manager_UnitChanged(Unit arg)
        {
            this.Board.UpdateUnit(arg);
        }

        void Manager_UnitLifeChanged(Unit unit, int argument)
        {
            if (argument < 0)
                this.Board.ShowDamageAnimation(unit, Math.Abs(argument));

            if (argument > 0)
                this.Board.ShowHealAnimation(unit, argument);
        }

        void Units_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
        {
            this.Board.RefreshUnits(this.Manager.Units);
        }

        void manager_BoardClear(BoardPointer dimension)
        {
            this.Board.Initialize(dimension.Column, dimension.Row);
        }

        void manager_BoardSetup(bool arg)
        {
            this.Board.SetupBoard(arg);
        }
    }
}
